package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BasePageData;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.wx.vo.AddOrDeleteBo;
import com.cskaoyan.service.CollectService;
import com.cskaoyan.utils.Constant;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/collect")
public class WxCollectController {

    @Autowired
    CollectService collectService;

    @RequestMapping("list")
    public BaseRespVo list(Byte type , Integer page , Integer limit){

        BasePageData basePageData = collectService.selectCollect(type , page , limit);

        return BaseRespVo.ok(basePageData);
    }


    @PostMapping("addordelete")
    public BaseRespVo addOrDelete(@RequestBody AddOrDeleteBo addOrDeleteBo){

        Byte type = addOrDeleteBo.getType();
        Integer valueId = addOrDeleteBo.getValueId();

        int code = collectService.addOrDelete(type , valueId );
        if (code == Constant.FAIL){
            return BaseRespVo.fail(501 , "请登录之后访问");
        }

        return BaseRespVo.ok();
    }
}
